<?php

class department_Model_DbTable_DbDepartment extends Zend_Db_Table_Abstract
{

    protected $_name = 'tbl_departments';
	//function for getting record user by user_id
    public function selectdpt(){
    	$db = new Application_Model_DbTable_DbGlobal();
    	//$db = $this->getAdapter();
    	$sql = "SELECT *,
    			(SELECT f.fac_name FROM tbl_faculty as f Where d.fac_id = f.fac_id) as fac_name
    			FROM tbl_departments as d ";
    	return $db->getGlobalDb($sql);
    }
    public function getpdt($id){
    	$db = $this->getAdapter();
    	$sql = "Select * From tbl_departments where dpt_id =".$id." LIMIT 1";
    	$rows = $db->fetchRow($sql);
		return $rows;
    }
	public function insertdp($arr)
	{ 
     	$array_data = array(
     			"fac_id"	=>	$arr["fac_id"],
     			"dpt_name"	=>	$arr["dpt_name"],  
     			"ordering"	=>	$arr["ordering"],
     			"description" =>$arr["description"],
     			"status" =>1,
     			"created_date"	=>	date("Y-m-d H:i:s")
     			);
     	$id=$this->insert($array_data);

	}
	public function updateStatus($arr)
	{
		$array_data = array(
				"dpt_id"	=>	$arr["dpt_id"],
				"status"	=>	1
		);
		$where = $this->getAdapter()->quoteInto('dpt_id=?', $arr["dpt_id"]);
		//echo $where; exit();
		$this->update($array_data, $where);
			
	}
	public function updateUnStatus($arr)
	{
		$array_data = array(
				"dpt_id"	=>	$arr["dpt_id"],
				"status"	=>	0
		);
		$where = $this->getAdapter()->quoteInto('dpt_id=?', $arr["dpt_id"]);
		//echo $where; exit();
		$this->update($array_data, $where);
			
	}
	public function updatedpt($arr)
	{
			$array_data = array(
     			"fac_id"	=>	$arr["fac_id"],
     			"dpt_name"	=>	$arr["dpt_name"],  
     			"ordering"	=>	$arr["ordering"],
     			"description" =>$arr["description"],
				"status" =>1,
     			"created_date"	=>	date("Y-m-d H:i:s")
     			);
			$where = $this->getAdapter()->quoteInto('dpt_id=?', $arr["dpt_id"]);
			$this->update($array_data, $where);
			//echo $where; exit();
	}
	public function deletepdt($id){
		$db = $this->getAdapter();
		$sql = "Delete From tbl_departments Where dpt_id=".$id;
		$row = $db->query($sql);
		return $row;
	}

}

